<html>

<head>
    <style type="text/css">
        table.gradienttable {
            font-family: verdana, arial, sans-serif;
            border-width: 3px;
            border-collapse: collapse;
            width: 100%;
        }
        
        table.gradienttable th {
            padding: 3px;
            color: #FFFFFF;
            background: #000066;
            font-size: 12px;
        }
        
        table.gradienttable td {
            padding: 3px;
            color: #000000;
            font-size: 11px;
            background: #ebecda;
            text-align: center;
        }
        
        table.gradienttable th p {
            margin: 3px;
            padding: 9px;
        }
        
        table.gradienttable td p {
            padding: 9px;
        }
    </style>
    <style>

    </style>

    <script>
        function openWeekSummary() {
            // 获取日期选择控件的值
            var date = document.getElementById('mydate').value;

            // 构建目标URL
            var url = '/task/weeksummary?date=' + encodeURIComponent(date);

            // 打开新窗口
            window.open(url, '_blank');
        }

        function refreshFeishu() {
            var selectedMan = document.querySelector('input[name="man"]:checked').value;
            var url = '/task/feishu?man=' + encodeURIComponent(selectedMan);
            window.location.href = url;
        }

        function refreshTapd() {
            var selectedMan = document.querySelector('input[name="man"]:checked').value;
            var url = '/task/tapdtask?man=' + encodeURIComponent(selectedMan);
            window.location.href = url;
        }


        
        function check() {
            // 获取日期选择控件的值
            var date = document.getElementById('mydate').value;

            // 构建目标URL
            var url = '/task/check?date=' + encodeURIComponent(date) + '&force=true';
            window.location.href = url;
        }
    </script>

    <script>
        // 用户点击查询按钮时保存选择的man到cookie
        function saveManToCookie() {
            console.log("saveManToCookie");
            var selectedMan = document.querySelector('input[name="man"]:checked');
            if (selectedMan) {
                // 保存到cookie，有效期7天
                document.cookie = "selectedMan=" + encodeURIComponent(selectedMan.value) + ";max-age=" + (7*24*60*60) + ";path=/";
            }
        }
        
        // 在查询按钮上添加onclick事件
        // 修改原来的查询按钮为：
        // <button type="submit" style="height:5em;width:7em;" onclick="saveManToCookie()">查询</button>
    </script>
</head>

<body>
    
    <style>
        /* 标签页样式 */
        .mainmanue {
            overflow: hidden;
            border: 1px solid #ccc;
            background-color: #f1f1f1;
            text-align: center;
        }
    
        .mainmanue button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            transition: 0.3s;
        }
    
        .mainmanue button:hover {
            background-color: #ddd;
        }
    
        .mainmanue button.active {
            background-color: #ccc;
        }
    
        .tabcontent {
            display: none;
            padding: 6px 12px;
            border: 1px solid #ccc;
            border-top: none;
        }
    </style>
    <div class="mainmanue" >
        <button class="tablinks" onclick="window.location.href='/task/home'">个人按日任务清单</button>
        <button class="tablinks" onclick="window.location.href='/task/weeksummary'">周任务统计(旧-实时查询)</button>
        <button class="tablinks" onclick="window.location.href='/devreport/list'">周任务统计(新-单据)</button>
        <button class="tablinks" onclick="window.location.href='/story/home'">需求统计</button>
    </div>
    <div style="width:1366px;margin-left:auto;margin-right:auto;">
        <!-- 可选人员:#for(x:mans)#(x) #end -->
        <!-- #(man) -->
        <div style="text-align:right;font-size:2em;">
            <form action="/task/home" method="get" style="text-align:left;">
                <p>
                    <label for="date">选择日期:</label>
                    <input type="date" id="mydate" name="date" value="" required style="font-size:1.5em;">
					#for(d:currentdates)
						<label>
							<input type="radio" name="currentdate" value='#date(d,"yyyy-MM-dd")' >#date(d,"MM/dd")
						</label>
					#end
                </p>
                <p>
                    #for(m:mans)
	                    <label>
                            <!-- 如果服务端没给man, 要能从cookies里读取之前选择的man并默认选中 -->
		                	<input type="radio" name="man" value="#(m)" onclick="saveManToCookie()" #if(man==m)checked#end>#(m)
                            
		            	</label>
					#end
                </p>
                <p style="text-align:right;">
                    <button type="button" style="height:5em;width:9em;" onclick="window.open('/empl/list','_blank')">用户设置</button>&nbsp;
                    <button type="button" style="height:5em;width:9em;" onclick="check()">未填报提醒</button>&nbsp;
                    <button type="button" style="height:5em;width:9em;" onclick="openWeekSummary()">周统计</button>&nbsp;
                    <button type="button" style="height:5em;width:9em;" onclick="refreshFeishu()" #if(importingstatus.rIsFeishuDoing) disabled #end>刷新飞书</button>&nbsp;
                    <button type="button" style="height:5em;width:12em;" onclick="refreshTapd()" #if(importingstatus.rIsTapdDoing) disabled #end>刷新TAPD</button>&nbsp;
                    <button type="submit" style="height:5em;width:7em;">查询</button>&nbsp;
                </p>
            </form>

            <script>
                // 设置日期输入框的默认值为当天日期
                document.getElementById('mydate').value = '#date(date,"yyyy-MM-dd")';
            </script>
        </div>

        <p>飞书最后导入时间:#date(importingstatus.rFeishuTime) , 飞书导入状态:#if(importingstatus.rIsFeishuDoing) 正在导入 #else 未在导入(未在导入也可能是没有新数据需要刷新) #end, TAPD最后导入时间:#date(importingstatus.rTapdTime), TAPD导入状态:#if(importingstatus.rIsTapdDoing) 正在导入 #else 未在导入 #end
        </p>
		<br>
        #if(man??)
        <div class="main">
            <!-- TAPD 当天完成任务清单 -->
            #include("/task/hometoday.html")
        </div>
        <div style="height:100px;"></div>
		<div class="main">
			<!-- 已开始未完成的任务 -->
			#include("/task/hometapdprogressing.html")
		</div>
        <div style="height:100px;""></div>
		<div class="main">
			<!-- 任务已完成,需求未标记完成的 -->
			#include("/task/hometapdstoryprogressing.html")
		</div>


        <div style="height:100px;""></div>
		<div class="main">
			<!-- 飞书本周工时统计 -->
			#include("/task/homefeishucurrentweek.html")
		</div>
		<div class="main">
			<!-- 飞书上周工时统计 -->
			#include("/task/homefeishupreweek.html")
		</div>
		<div style="height:100px;""></div>
        <div class="main">
            <!-- TAPD本周工时统计 -->
            #include("/task/hometapdcurrentweek.html")
        </div>
        <div style="height:100px;""></div>
		<div class="main">
			<!-- TAPD上周工时统计 -->
			#include("/task/hometapdpreweek.html")
		</div>
		<div style="height:100px;""></div>
        <div class="main">
            <!-- TAPD过去一个月工时统计 -->
            #include("/task/hometapdcurrentmonth.html")
            <!-- TODO 绩效预估 -->
        </div>
        <div style="height:100px;""></div>
		<div class="main">
			<!-- TAPD本周完成任务 -->
			#include("/task/hometapdcurrentweektask.html")
		</div>
		<div style="height:100px;""></div>
        <div class="main">
            <!-- TAPD上周完成任务 -->
            #include("/task/hometapdpreweektask.html")
        </div>

        <div style="height:100px;""></div>
		<div class="main">
			<!-- TAPD未完成任务 -->
			#include("/task/hometapdemergencytask.html")
		</div>


        
        <div style="height:100px;""></div>
		<div class="main">
			<!-- 飞书记录 -->
			#include("/task/homefeishulist.html")
		</div>

        
        <div style="height:100px;""></div>
		<div class="main">
			<!-- 绩效估计 -->
			#include("/task/hometapdperformance.html")
		</div>


#end		
</div>
<script>
    // 设置日期输入框的默认值为当天日期
    document.getElementById('mydate').value = '#date(date,"yyyy-MM-dd")';
    
    // 从cookie中获取man的值
    function getCookie(name) {
        let cookies = document.cookie.split(';');
        for(let i = 0; i < cookies.length; i++) {
            let cookie = cookies[i].trim();
            if (cookie.indexOf(name + '=') === 0) {
                return cookie.substring(name.length + 1);
            }
        }
        return null;
    }
    
    // 如果服务端没有设置man，则从cookie中读取
    window.addEventListener('load', function() {
        var manRadios = document.querySelectorAll('input[name="man"]');
        var serverMan = '#(man)'; // 服务端提供的man值
        console.log('serverMan:', serverMan);
        // 如果服务端没有提供man
        if (!serverMan || serverMan === '') {
            var cookieMan = getCookie('selectedMan');
            if (cookieMan) {
                cookieMan = decodeURIComponent(cookieMan);
                console.log('cookieMan:', cookieMan);
                // 设置cookie中保存的选项为选中状态
                for (var i = 0; i < manRadios.length; i++) {
                    if (manRadios[i].value === cookieMan) {
                        manRadios[i].checked = true;
                        break;
                    }
                }
            }
        }
    });
</script>
</body>
</html>